package cn.iocoder.yudao.module.home.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;

import cn.iocoder.yudao.module.home.controller.admin.vo.*;
import cn.iocoder.yudao.module.home.service.HomeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;
import java.util.List;

@Tag(name = "后台首页请求")
@RestController
@RequestMapping("/home")
@Validated
public class HomeController {

    @Resource
    private HomeService homeService;

    @GetMapping("/top-index")
    @Operation(summary = "获取首页TOP指标数据")
    public CommonResult<HomeTopIndexRespVO> getTopIndex() {
        HomeTopIndexRespVO result = homeService.getTopIndex();
        return CommonResult.success(result);
    }
    @GetMapping("/portal/top-index")
    @Operation(summary = "获取首页TOP指标数据")
    @PermitAll
    public CommonResult<HomeTopIndexRespVO> getPortalTopIndex() {
        HomeTopIndexRespVO result = homeService.getTopIndex();
        return CommonResult.success(result);
    }

    @GetMapping("/section-options")
    @Operation(summary = "根据层级获取图表配置选项")
    @Parameter(name = "hierarchy", description = "层级名称，如：汇聚层、数据层等", required = true, example = "汇聚层")
    public CommonResult<List<SectionOptionVO>> getSectionOptions(@RequestParam String hierarchy) {
        List<SectionOptionVO> result = homeService.getSectionOptions(hierarchy);
        return CommonResult.success(result);
    }
    @GetMapping("/access-statistics")
    @Operation(summary = "获取系统接入情况统计")
    public CommonResult<AccessStatisticsRespVO> getAccessStatistics() {
        AccessStatisticsRespVO result = homeService.getAccessStatistics();
        return CommonResult.success(result);
    }
    @PostMapping("/catalog-index")
    @Operation(summary = "获取目录指标数据")
    public CommonResult<List<CatalogIndexItemVO>> getCatalogIndex(@Valid @RequestBody CatalogIndexReqVO reqVO) {
        List<CatalogIndexItemVO> result = homeService.getCatalogIndex(reqVO);
        return CommonResult.success(result);
    }
    @PostMapping("/catalog-index-details")
    @Operation(summary = "获取目录指标详情数据（分页）")
    public CommonResult<CatalogIndexDetailsRespVO> getCatalogIndexDetails(@Valid @RequestBody CatalogIndexDetailsReqVO reqVO) {
        CatalogIndexDetailsRespVO result = homeService.getCatalogIndexDetails(reqVO);
        return CommonResult.success(result);
    }
    @PostMapping("/table-ranking")
    @Operation(summary = "获取表数据排名")
    public CommonResult<TableRankingRespVO> getTableRanking(@Valid @RequestBody TableRankingReqVO reqVO) {
        TableRankingRespVO result = homeService.getTableRanking(reqVO);
        return CommonResult.success(result);
    }
    @GetMapping("/task-distribution")
    @Operation(summary = "获取汇聚任务分布统计")
    public CommonResult<TaskDistributionRespVO> getTaskDistribution() {
        TaskDistributionRespVO result = homeService.getTaskDistribution();
        return CommonResult.success(result);
    }
    @GetMapping("/data-num-7day")
    @Operation(summary = "获取7天数据量统计")
    public CommonResult<List<DataNum7DayItemVO>> getDataNumBy7Day() {
        List<DataNum7DayItemVO> result = homeService.getDataNumBy7Day();
        return CommonResult.success(result);
    }
    @GetMapping("/data-sources")
    @Operation(summary = "获取数据源列表")
    public CommonResult<List<DataSourceVO>> getDataSources() {
        List<DataSourceVO> result = homeService.getDataSources();
        return CommonResult.success(result);
    }
    @GetMapping("/data-std-statistics")
    @Operation(summary = "获取数据标准统计")
    public CommonResult<DataStdStatisticsRespVO> getDataStdStatistics() {
        DataStdStatisticsRespVO result = homeService.getDataStdStatistics();
        return CommonResult.success(result);
    }
}